package cn.shun.controller;

import cn.hutool.core.util.ObjUtil;
import cn.shun.dao.WareHouseDao;
import cn.shun.local.LocalUserThreadLocal;
import cn.shun.model.LocalUser;
import cn.shun.model.WareHouse;
import cn.shun.model.WareHouseQuery;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/api/warehouse")
public class WareHouseController {

    @Resource
    private WareHouseDao dao;

    @GetMapping
    public List<WareHouse> select(WareHouseQuery query) {
        //如果前端你不传status，那么我默认查询状态是1的列表
        if (ObjUtil.isEmpty(query.getStatus())) {
            query.setStatus(1);
        }
        return dao.select(query);
    }

    @PostMapping
    public Integer insert(@RequestBody WareHouse vendor) {
        LocalUser localUser = LocalUserThreadLocal.get();
        vendor.setLastUpdateBy(localUser.getTel());
        return dao.insert(vendor);
    }

    @PutMapping
    public Integer update(@RequestBody WareHouse vendor) {
        LocalUser localUser = LocalUserThreadLocal.get();
        vendor.setLastUpdateBy(localUser.getTel());
        return dao.update(vendor);
    }

    @DeleteMapping
    public Integer delete(@RequestParam Integer id) {
        return dao.delete(id);
    }


}